package com.esgov.chatbot.api;


import com.esgov.chatbot.entity.chatbot.*;
import com.esgov.chatbot.entity.chatbot.chat.ChatRequest;
import com.esgov.chatbot.entity.chatbot.chat.ChatResponse;
import com.esgov.chatbot.service.TChatbotSessionService;
import com.esgov.chatbot.support.ResponseResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * <p>
 * 文本机器人会话 前端控制器
 * </p>
 *
 * @author Eric Lao
 * @since 2025-09-16
 */
@RestController
@Api(tags = "在线客服作业相关接口")
@RequestMapping("/chatBot")
public class TChatbotSessionController {

    @Resource
    private TChatbotSessionService tChatbotSessionService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("创建机器人会话")
    @PostMapping("/createChatBotSession")
    public ResponseResult<CreateChatBotSessionResponse> createChatBotSession(@RequestBody @Validated CreateChatBotSessionRequest request) {
        return ResponseResult.success(tChatbotSessionService.createChatBotSession(request));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("结束机器人会话")
    @PostMapping("/endChatBotSession")
    public ResponseResult<Void> endChatBotSession(@RequestBody @Validated EndChatBotSessionRequest request) {
        tChatbotSessionService.endChatBotSession(request);
        return ResponseResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("FAQ反馈接口")
    @PostMapping("/feedback")
    public ResponseResult<FeedbackResponse> feedback(@Validated @RequestBody FeedbackRequest request) {
        return ResponseResult.success(tChatbotSessionService.feedback(request));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("人机对话接口")
    @PostMapping("/chat")
    public ResponseResult<ChatResponse> chat(@RequestBody @Validated ChatRequest request) {
        return ResponseResult.success(tChatbotSessionService.chat(request));
    }

    @ApiOperation(value = "对话窗口", hidden = true)
    @GetMapping("/index")
    public ModelAndView chat() {
        return new ModelAndView("chat");
    }
}

